package com.itheima.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * @Author 王加鑫
 * @Date 2021/5/25 11:38
 * @Version 1.0
 */
public class Server01 {
    public static void main(String[] args) throws IOException {
        //创建Socket对象
        MulticastSocket ms = new MulticastSocket(10000);
        //创建Packet对象
        DatagramPacket packet = new DatagramPacket(new byte[1024],1024);
        //把当前计算机绑定一个组播地址,表示添加到这一组中
        InetAddress address = InetAddress.getByName("224.0.1.0");
        ms.joinGroup(address);
        //接收数据
        ms.receive(packet);

        System.out.println(new String(packet.getData(),0,packet.getLength()));

        ms.close();
    }
}
